<?php

$base_url = base_url();
$images_url = base_url('images');
$uploads_url = base_url('uploads');
$admin_url = base_url('otakkanan');
$kirim_url = base_url('otakkiri');

$other_head = "
	<script type='text/javascript'>
		
		function form_validate(form){
			if(form.judul.value==''){ alert('Judul Harus Diisi'); form.judul.focus(); return false; }
			if(form.promosi.value==''){ alert('promosi harus diisi'); form.promosi.focus(); return false; }
			if(form.berakhir.value==''){ alert('Batas waktu harus diisi'); form.berakhir.focus(); return false; }
		}
		
		\$jq(function(){
			\$jq('#berakhir').datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'yy-mm-dd'
			});
		});
	
	</script>
";

$menu = $this->uri->segment(3, "");
$mapdir = "
	<a href='$admin_url/'>Home</a>
";

switch($menu){
	case "edit":
		$mapdir .= "
			&nbsp; &gt;&gt; 
			<a href='$admin_url/promosi'>Promosi Usaha</a>
			&nbsp; &gt;&gt; 
			<b>Edit Promosi</b>
		";
		
		$idp = $this->input->get('idp');
		$hasil = $this->adminmodel->getDataWhere('dn_promote',array('idpromosi'=>$idp));
		
		if($hasil != false){
			foreach($hasil AS $hasil2){
				$idp = $hasil2->idpromosi;
				$judul = $hasil2->judul;
				$promosi = $hasil2->promosi;
				$gambar = $hasil2->gambar;
				$berakhir = $hasil2->berakhir;
				
				$tampil = "
							<tr>
								<td class='left'>judul * : </td>
								<td class='right'><input name='judul' type='text' value='$judul'  /></td>
							</tr>
							<tr>
								<td class='left'>Promosi Anda * : </td>
								<td class='right'><textarea name='promosi' cols='30' rows='5'>$promosi</textarea></td>
							</tr>
							<tr>
								<td class='left'>Berakhir * : </td>
								<td class='right'><input type='text' name='berakhir' id='berakhir' value='$berakhir' />
									<div class='note'>format : yyyy-mm-dd</div>
								</td>
							</tr>
							<tr>
								<td class='left'>Gambar : </td>
								<td class='right'><input name='gambar' type='file' />
								<br /><div class='keterangan'>Anda juga dapat mengubah Gambar (kosongkan jika tidak akan diubah). ukuran maksimal dimensi gambar adalah 1000px X 1000px. gambar yang diperbolehkan adalah jpg, bmp, gif dan kurang dari 1 MB.</div></td>
							</tr>
						
							<tr>
								<td class='left'>&nbsp;</td>
								<td class='right'>Tanda Bintang (*) berarti Kolom wajib Diisi</td>
							</tr>
							<tr>
								<td class='left'> &nbsp; </td>
								<td class='right'><input type='hidden' name='idp' value='$idp' /><input type='hidden' name='oldgambar' value='$gambar' />
								<input type='submit' value='Ubah'> &nbsp; <input type='reset' value='Ulang'></td>
							</tr>";
			}
		}else{
			$tampil = "<tr>
							<td class='left'>&nbsp;</td>
							<td class='right'>Data Tidak Ditemukan</td>
						</tr>";
		}
		
		$isipage = "
				<div id='content2'>
						<h3>Edit Produk</h3>
							<div class='isicontent2'>
							
							  <form id='FrmMasukan' action='$kirim_url/updatepromosi' method='post' enctype='multipart/form-data' >
								
									<table>
										<tbody>
										
											$tampil
										
										</tbody>
									</table>
									
							  </form>
							</div>
							
						</div>
			";
	;
	break;
	
	case "baru":
		$mapdir .= "
			&nbsp; &gt;&gt; 
			<a href='$admin_url/promosi'>Promosi Usaha</a>
			&nbsp; &gt;&gt; 
			<b>Promosi Baru</b>
		";
		
		$isipage = "
					
				<div id='content2'>
						<h3>Tambah Produk Baru</h3>
						<div class='isicontent2'>
							 <img class='pcc' alt='Logo Dadan Network' src='$images_url/logoo.png' width='20%'>
							  
							  <br>
							  <p>
								<b>Perhatian!</b> halaman ini adalah untuk menambah Promosi untuk perusahaan <a href='$admin_url/perusahaan/detail?idc=1'>Dadan Network</a>. Jika anda ingin membuat promosi untuk perusahaan lain, maka yang perlu anda lakukan adalah masuk ke <a href='$admin_url/perusahaan/'>halaman perusahaan</a>, kemudian klik detail dan klik link buat promosi.
							  </p>
						</div>
						
							<div class='isicontent2'>
							
							  <form id='FrmMasukan' action='$kirim_url/promosibaru' method='post' onsubmit='return form_validate(this)'  enctype='multipart/form-data'  >
								
									<table>
										<tbody>
											<tr>
												<td class='left'>judul * : </td>
												<td class='right'><input name='judul' type='text' placeholder='Judul' /></td>
											</tr>
											<tr>
												<td class='left'>Promosi Anda * : </td>
												<td class='right'><textarea name='promosi' placeholder='Promosi Anda' cols='30' rows='5'></textarea></td>
											</tr>
											<tr>
												<td class='left'>Berakhir * : </td>
												<td class='right'><input type='text' name='berakhir' id='berakhir' />
													<div class='note'>format : yyyy-mm-dd</div>
												</td>
											</tr>
											<tr>
												<td class='left'>Gambar : </td>
												<td class='right'><input name='gambar' type='file' />
												<br /><div class='keterangan'>Anda juga dapat menambahkan gambar produk. ukuran maksimal dimensi gambar adalah 1000px X 1000px. gambar yang diperbolehkan adalah jpg, bmp, gif dan kurang dari 1 MB.</div></td>
											</tr>
											
											<tr>
												<td class='left'>&nbsp;</td>
												<td class='right'>Tanda Bintang (*) berarti Kolom wajib Diisi</td>
											</tr>
											<tr>
												<td class='left'> &nbsp; </td>
												<td class='right'>
												<input type='submit' value='Tambah'> &nbsp; <input type='reset' value='Ulang'></td>
											</tr>
										
										</tbody>
									</table>
									
							  </form>
							</div>
							
						</div>
			";
		
	;
	break;
	
	case "detail":
		$mapdir .= "
			&nbsp; &gt;&gt; 
			<a href='$admin_url/promosi'>Promosi Usaha</a>
			&nbsp; &gt;&gt; 
			<b>Detail</b>
		";
		
		$idp = $this->input->get('idp');
		$hasil = $this->adminmodel->getDataWhere('dn_promote',array('idpromosi'=>$idp));
		
		if($hasil != false){
			foreach($hasil AS $hasil2){
				$judul = filter_var($hasil2->judul, FILTER_SANITIZE_STRING);
				$promosi = xss_clean($hasil2->promosi);
				$gambar = $hasil2->gambar;
				$berakhir = date("d M Y", strtotime($hasil2->berakhir));
				
				if($gambar != ""){
					$gambar = "$uploads_url/promosi/$gambar";
				}else{
					$gambar = "$images_url/noimages.gif";
				}
				
				
				$tampil = "<tr>
								<td class='left'>Judul </td>
								<td class='right'>$judul</td>
							</tr>
							<tr>
								<td class='left'>Promosi </td>
								<td class='right'>$promosi</td>
							</tr>
							<tr>
								<td class='left'>Berakhir </td>
								<td class='right'>$berakhir</td>
							</tr>
							<tr>
								<td class='left'>Gambar : </td>
								<td class='right'><img alt='Gambar Produk' src='$gambar' class='preview' /></td>
							</tr>
							
							<tr>
								<td class='left'>&nbsp;</td>
								<td class='right'>&nbsp;</td>
							</tr>
							<tr>
								<td class='left'> &nbsp; </td>
								<td class='right'><a href='javascript:history.go(-1)'>&lt;&lt; Kembali</a></td>
							</tr>";
			}
		}else{
			$tampil = "<tr>
							<td class='left'>&nbsp;</td>
							<td class='right'>Data Tidak Ditemukan</td>
						</tr>";
		}
		
		$isipage = "
				<div id='content2'>
						<h3>Detail Perusahaan</h3>
							<div class='isicontent2'>
							
								<table>
									<tbody>
									
										$tampil
									
									</tbody>
								</table>
									
							</div>
							
						</div>
			";
	;
	break;
	
	default:
		$mapdir .= "
			&nbsp; &gt;&gt; 
			<b>Promosi</b>
		";
		
		$awal = $this->input->get("awal",0);
		$promosi = $this->adminmodel->getDataOrder($awal,'dn_promote',20,'idpromosi','desc');
		$datapromosi = "";
		
		if($promosi != false){
			foreach($promosi AS $pdata){
				$id = $pdata->idpromosi;
				$judul = $pdata->judul;
				
				$datapromosi .= "<tr><td class='left'>$judul</td><td class='right'> <a href='$admin_url/promosi/detail?idp=$id'>Detail</a> &nbsp; <a href='$admin_url/promosi/edit?idp=$id'>Edit</a> &nbsp; <a href='$kirim_url/hapuspromosi?idp=$id'>Hapus</a></td></tr>";
			}
		}else{
			$datapromosi = "<tr><td class='left'>&nbsp;</td><td class='right'>Belum ada Promosi. <a href='$admin_url/promosi/baru'>Buat Promosi?</a></td></tr>";
		}
		
		$config['base_url'] = $admin_url.'/promosi?usaha=maju';
		$config['total_rows'] = $this->adminmodel->hitungData('idpromosi','dn_promote');
		$config['per_page'] = 20; 
		$config['page_query_string'] = TRUE;
		$config['query_string_segment'] = 'awal';

		$this->pagination->initialize($config); 
		$halaman = $this->pagination->create_links();
		
		$isipage = "
				<div id='content2'>
						<h3>Daftar Produk</h3>
							<div class='isicontent2'>
							 <table>
								<tbody>
									<tr><td class='left'><a href='$admin_url/promosi/baru'>Tambah Baru</a></td><td class='right'>&nbsp;</td></tr>
									<tr><td class='left'>&nbsp;</td><td class='right'>&nbsp;</td></tr>
									$datapromosi
									<tr><td class='left'>&nbsp;</td><td class='right'>&nbsp;</td></tr>
									<tr><td class='left'><a href='$admin_url/promosi/baru'>Tambah Baru</a></td><td class='right'>$halaman</td></tr>
								</tbody>
							 </table>
							</div>
							
					</div>
			";
	;
	break;
}





$data = array(
	'site_title'=>lang('site_title').' - Promosi',
	'robot_content'=>'NOINDEX, NOFOLLOW',
	'base_url'=> base_url(),
	'other_head'=>$other_head,
	'map_dir'=>$mapdir,
	'isi_page'=>$isipage,
	'tahun_sekarang'=>date("Y")
);
$this->parser->parse('template/admin', $data);


/* End of file promosi.php */
/* Location: ./application/views/admin/promosi.php */
